import JSEncrypt from "jsencrypt";

// JSEncrypt加密
const encrypt = function (data, publicKey) {
  var encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey);
  // 如果是对象/数组的话，需要先JSON.stringify转换成字符串
  var result = encryptor.encrypt(data);
  return result;
};

// JSEncrypt解密
const decrypt = function (data, publicKey) {
  var encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey);
  // 如果是对象/数组的话，需要先JSON.stringify转换成字符串
  var result = encryptor.decrypt(data);
  return result;
};

export default {
  encrypt,
  decrypt,
};
